package com.batchaps.classes;

import java.util.Vector;

import javax.microedition.lcdui.Graphics;

import com.batchaps.global.GameEngine;

public class MyPlayer {
	private Sprite2D mySprite2D;
	private Vector myPath;
	private int type;
	
	private int width;
	private int height;
	
	public boolean isMove;

	public MyPlayer(String sp , int nSp , String strType , float pX , float pY , float sX , float sY , int w , int h){
		mySprite2D = new Sprite2D(sp, nSp, strType, w, h, sX, sY, pX, pY);
		myPath = new Vector();
		width = w;
		height = h;
		isMove = false;
	}
	
	public void Move(int ty , int targetX , int targetY){
		if(isMove){
			switch(ty){
			case 1://top
				if(mySprite2D.MoveTo(ty, targetX, targetY)){
					if(ty == 1){
						myPath.addElement(new Path(1 , targetX , targetY , GameEngine.PATH_SIZEX, GameEngine.PATH_SIZEY , width , height));
					}else{
						myPath.addElement(new Path(3 , targetX , targetY , GameEngine.PATH_SIZEX, GameEngine.PATH_SIZEY , width , height));
					}
				}
				break;
			case 2://right
				if(mySprite2D.MoveTo(ty, targetX, targetY)){
					if(ty == 2){
						myPath.addElement(new Path(2 , targetX , targetY , GameEngine.PATH_SIZEX, GameEngine.PATH_SIZEY , width , height));
					}else{
						myPath.addElement(new Path(3 , targetX , targetY , GameEngine.PATH_SIZEX, GameEngine.PATH_SIZEY , width , height));
					}
				}
				break;
			case 3://down
				if(mySprite2D.MoveTo(ty, targetX, targetY)){
					if(ty == 2){
						myPath.addElement(new Path(1 , targetX , targetY , GameEngine.PATH_SIZEX, GameEngine.PATH_SIZEY , width , height));
					}else{
						myPath.addElement(new Path(3 , targetX , targetY , GameEngine.PATH_SIZEX, GameEngine.PATH_SIZEY , width , height));
					}
				}
				break;
			case 4://left
				if(mySprite2D.MoveTo(ty, targetX, targetY)){
					if(ty == 2){
						myPath.addElement(new Path(2 , targetX , targetY , GameEngine.PATH_SIZEX, GameEngine.PATH_SIZEY , width , height));
					}else{
						myPath.addElement(new Path(3 , targetX , targetY , GameEngine.PATH_SIZEX, GameEngine.PATH_SIZEY , width , height));
					}
				}
				break;
			}
		}
	}
	
	public void Draw(Graphics g){
		mySprite2D.Draw(g);
		for(int i = 0 ; i < myPath.size() ;i++){
			((Path)myPath.elementAt(i)).DrawPath(g);
		}
	}

	/**
	 * @return the mySprite2D
	 */
	public Sprite2D getMySprite2D() {
		return mySprite2D;
	}

	/**
	 * @param mySprite2D the mySprite2D to set
	 */
	public void setMySprite2D(Sprite2D mySprite2D) {
		this.mySprite2D = mySprite2D;
	}
	
	/**
	 * @return the type
	 */
	public int getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(int type) {
		this.type = type;
	}

	/**
	 * @return the width
	 */
	public int getWidth() {
		return width;
	}

	/**
	 * @param width the width to set
	 */
	public void setWidth(int width) {
		this.width = width;
	}

	/**
	 * @return the height
	 */
	public int getHeight() {
		return height;
	}

	/**
	 * @param height the height to set
	 */
	public void setHeight(int height) {
		this.height = height;
	}

	/**
	 * @return the myPath
	 */
	public Vector getMyPath() {
		return myPath;
	}

	/**
	 * @param myPath the myPath to set
	 */
	public void setMyPath(Vector myPath) {
		this.myPath = myPath;
	}
}
